<!DOCTYPE HTML>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="renderer" content="webkit|ie-comp|ie-stand">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
		<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
		<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
		<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
		<link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
		<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
		<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
		<title>车辆二维码列表</title>
	</head>

	<body>
		<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
			<span class="c-gray en">&gt;</span> 基础信息管理
			<span class="c-gray en">&gt;</span> 车辆二维码管理
			<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);"
			 title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
		</nav>
		<div class="page-container" id="app">
			<div class="text-c">
				<!--<button onclick="removeIframe()" class="btn btn-primary radius">关闭选项卡</button>--> 分公司:
				<span class="select-box inline">
					<select class="select" id="comId" name="comId">
						<option value="">请选择分公司</option>
					</select>
				</span> <!--票务室:
			 	<span class="select-box inline">
					<select class="select" id="toId" name="toId">
						<option value="">请选择票务室</option>
					</select>
				</span> -->
				<input type="text" name="" id="query" placeholder="车辆号" style="width:250px" class="input-text" v-model="msg">
				<button name="" id="" class="btn btn-success" type="submit" v-on:click="query()"><i class="Hui-iconfont">&#xe665;</i>
					搜索</button>
					

			</div>
			<div  id="divId" class="cl pd-5 bg-1 bk-gray mt-20">
				<span class="l" v-if="hasRole('ADMIN')">
					<a href="javascript:;" onclick="delectVehicleQrcodeByIds()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 删除</a>
					<button name="" id="vehicleCreater" class="btn btn-success" type="submit" onclick="submitall();">生成</button>
				</span>
				<span class="l">
					<a id="parentDom" class="btn btn-warning radius" href="javascript:;" onclick="vehicle_updateMoreById('批量需改','baseinfo-vehicle-qrcode-update.html','','','500')"><i
						 class="Hui-iconfont">&#xe6df;</i> 批量修改</a><!--  onclick="cashbox_updateMoreById()" -->
					<button name="" id="excelId" class="btn btn-success" type="submit" onclick="excelAll();">导出Excel</button>
				</span>
			</div>
			<div class="mt-20">
				<table id="list" class="table table-border table-bordered table-hover table-bg table-sort">
				</table>
			</div>
		</div>
		<!--_footer 作为公共模版分离出去-->
		<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
		<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
		<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
		<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script>
		<!--/_footer 作为公共模版分离出去-->

		<!--请在下方写此页面业务相关的脚本-->
		<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
		<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.js"></script>
		<script type="text/javascript" src="js/vue.js" charset="utf-8"></script>
		<script type="text/javascript" src="js/jquery.base64.js"></script>
		<script type="text/javascript" src="js/jquery.table2excel.js"></script>
		<script type="text/javascript">
			//本地调试
			//var urlsCashbox = 'http://localhost:8000/cashbox/';
			//var urlsVVehicleqrcode = 'http://192.168.3.20:8000/vvehicleqrcode/';
			//调用report服务中的分公司与票务室方法
			//var urlsReport = 'http://localhost:8800/report/';
			//阿里云调试
			var urlsReport = 'http://39.100.91.49:8800/report';
			//上线部署
			//var urlsVehicleqrcode = 'http://192.168.1.106:8000/vehicleqrcode/';
			var urlsVehicleqrcode = '/apis/base/vehicleqrcode/';
			var urlsVVehicleqrcode = '/apis/base/vvehicleqrcode/';
			
			
			var username =window.localStorage.getItem("user_name");
			var comanyId ="";
			
			var comId="";
			var toId="";	
		$(function() {
			$.ajax({
				type: 'get',
				url: urlsReport+'/getAllCompany',
				 beforeSend: function (request) {
								request.setRequestHeader("Authorization", "Bearer " + getToken());
							}, 
				dataType: 'json',
				async: false,
				success: function(data){
					var list =  eval('(' + data.list + ')');
					for(var i = 0;i<list.length;i++){
						$("#comId").append("<option value='"+list[i].companyid+"'>"+list[i].companyname+"</option>");				
					}
				},
				error: function(data){
					console.log(data.msg);
				}
			});
			
			$.ajax({
				type: 'get',
				url: urlsReport+'/getUserByname',
				data:{
					"username":username
				},
				async: false,
				beforeSend: function (request) {
								request.setRequestHeader("Authorization", "Bearer " + getToken());
							}, 
				dataType: 'json',
				success: function(data){
					console.log(""+data.list);
					var list =  eval('(' + data.list + ')');
					console.log(list)
					if(list[0].officeId.indexOf("1")==0){
						$("#comId").val(list[0].companyId);
						comId = list[0].companyId;
						/* var comLength = $("#comId option").length;
						console.log($("#comId option[index='"+i+"']").val); */
						
						$.ajax({
							type: 'get',
							url: urlsReport+'/getTicktOfficeByCom',
							 beforeSend: function (request) {
											request.setRequestHeader("Authorization", "Bearer " + getToken());
										}, 
							data:{
								"comId":comId
							},
							cache:false,    
							dataType:'json',
							async: false,
							success: function(data){
								//var list = data.list;
								var list =  eval('(' + data.list + ')');
								for(var i=0;i<list.length;i++){
									var option = '<option value="'+list[i].toiid+'">'+list[i].toiname+'</option>';
									$("#toId").append(option);
								}
							},
							error:function(){
								alert("请求失败");
							}
						});
						$("#toId").val(list[0].officeId);
						toId = list[0].officeId;
						$("#comId").attr("disabled","disabled");
						$("#toId").attr("disabled","disabled");
					}
					if(list[0].officeId.indexOf("1") == -1  && list[0].companyId.indexOf("1")==0 ){
						$("#comId").val(list[0].companyId);
						comId = list[0].companyId;
						$.ajax({
							type: 'get',
							url: urlsReport+'/getTicktOfficeByCom',
							 beforeSend: function (request) {
											request.setRequestHeader("Authorization", "Bearer " + getToken());
										}, 
							data:{
								"comId":comId
							},
							cache:false,    
							dataType:'json',
							async: false,
							success: function(data){
								//var list = data.list;
								var list =  eval('(' + data.list + ')');
								for(var i=0;i<list.length;i++){
									var option = '<option value="'+list[i].toiid+'">'+list[i].toiname+'</option>';
									$("#toId").append(option);
								}
							},
							error:function(){
								alert("请求失败");
							}
						});
						$("#comId").attr("disabled","disabled");
					}
					
					
				},
				error: function(data){
					console.log(data.msg);
				}
			});
		})
			
			var vm = new Vue({
				el: "#app",
				data: {
					msg: ""
				},
				//在实例初始化之后，数据观测 (data observer) 和 event/watcher 事件配置之前被调用。
				beforeCreate: function() {
					console.log('beforeCreate');
				},
				/* 在实例创建完成后被立即调用。
				在这一步，实例已完成以下的配置：数据观测 (data observer)，属性和方法的运算，watch/event 事件回调。
				然而，挂载阶段还没开始，$el 属性目前不可见。 */
				created: function() {
					console.log('created');
				},
				//在挂载开始之前被调用：相关的渲染函数首次被调用
				beforeMount: function() {
					console.log('beforeMount');

				},
				//el 被新创建的 vm.$el 替换, 挂在成功	
				mounted: function() {
					console.log('mounted');

				},
				//数据更新时调用
				beforeUpdate: function() {
					console.log('beforeUpdate');

				},
				//组件 DOM 已经更新, 组件更新完毕 
				updated: function() {
					console.log('updated');

				},
				methods: {
					hasRole: function(role) {
						var authorities = window.localStorage.getItem("authorities");
						if(authorities.indexOf("ROLE_" + role) >= 0) {
							return true;
						} else {
							return false;
						}
					},
					hasAnyRole: function() {
						var authorities = window.localStorage.getItem("authorities");
						for(var i = 0; i < arguments.length; i++) {
							if(authorities.indexOf("ROLE_" + arguments[i]) >= 0) {
								return true;
							}
						}
						return false;
					},
					query: function() {
						var com = 	$("#comId").val();
						var vehicleid = this.msg
						var data = {};
						if (com != '') {
							data.comid = com;
						}
						if (vehicleid != '') {
							data.id = vehicleid;
						}
						if(this.msg!=null&&this.msg!=""&&com!=null&&com!=""){
							$.ajax({
								type: 'GET',
								url: urlsVVehicleqrcode + 'vgetTableList',
								data: data,
								 beforeSend: function(request) {
									request.setRequestHeader("Authorization", "Bearer " + getToken());
								}, 
								dataType: 'json',
								success: function(data) {
									 table.fnClearTable(); //将数据清除
									if (data.data.length > 0) {
										table.fnAddData(data.data, true); //数据必须是json对象或json对象数组
									} 
								},
								error: function(data) {
									console.log(data.msg);
								},
							});
						}else if(com!=null&&com!=""){
							$.ajax({
								type: 'GET',
								url: urlsVVehicleqrcode + 'vgetTableList',
								data: {
									"comid": com,
									"order": "serialNum"
								},
								 beforeSend: function(request) {
									request.setRequestHeader("Authorization", "Bearer " + getToken());
								}, 
								dataType: 'json',
								success: function(data) {
									 table.fnClearTable(); //将数据清除
									if (data.data.length > 0) {
										table.fnAddData(data.data, true); //数据必须是json对象或json对象数组
									} 
								},
								error: function(data) {
									console.log(data.msg);
								},
							});
						
						}else{
							$.ajax({
								type: 'GET',
								url: urlsVVehicleqrcode + 'vgetTableList',
								data: {
									"order": "serialNum"
								},
								 beforeSend: function(request) {
									request.setRequestHeader("Authorization", "Bearer " + getToken());
								}, 
								dataType: 'json',
								success: function(data) {
									 table.fnClearTable(); //将数据清除
									if (data.data.length > 0) {
										table.fnAddData(data.data, true); //数据必须是json对象或json对象数组
									} 
								},
								error: function(data) {
									console.log(data.msg);
								},
							});
						}
						
					}
				}
			});

			var table = $('#list').dataTable({
				"bProcessing": true, //DataTables载入数据时，是否显示‘进度’提示  
				"bAutoWidth": true, //是否自适应宽度  
				/* "aLengthMenu": [20, 50, 100, 200, 500, 1000, 5000], //更改显示记录数选项  
				"iDisplayLength": 20, //默认显示的记录数 */
				"lengthMenu":[10, 50, 100],
				"pageLength": 100,
				"aaSorting": [
					[3, "asc"]
				], //默认第几个排序
				//"bStateSave": true, //状态保存
				"aoColumnDefs": [
					//{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
					{
						"orderable": false,
						"aTargets": [0, 4]
					} // 制定列不参与排序
				],
				bDeferRender: true,
				"aoColumns": [{
					"mDataProp": "id",
					"sTitle": "<input type='checkbox'  class='check_item'  name=''value=''/>",
					"sDefaultContent": "" ,//此列默认值为""，以防数据中没有此值，DataTables加载数据的时候报错  
					// "sClass": "text-center"
					// "bVisible" : false //此列不显示  
					"render": function(data, type, row, meta) {
						return '<input  class="check_item"   id="(\'' + row.id + '\')" value="'+row.id+'" name="qrcodeid" type="checkbox" />'

					}
				}, {
					"mDataProp": "companyName",
					"sTitle": "分公司",
					"sDefaultContent": "",
					"sClass": "center"
				}, /* {
					"mDataProp": "office.officename",
					"sTitle": "票务室",
					"sDefaultContent": "",
					"sClass": "center"
				}, */
				{
					"mDataProp": "teamName",
					"sTitle": "车队",
					"sDefaultContent": "",
					"sClass": "center"
				},
				{
					"mDataProp": "serialNum",
					"sTitle": "编号",
					"sDefaultContent": "",
					"sClass": "center"
				},
				{
					"mDataProp": "vehiclenum",
					"sTitle": "车辆号",
					"sDefaultContent": "",
					"sClass": "center"
				},
				{
					"mDataProp": "status",
					"sTitle": "状态",
					"sDefaultContent": "",
					"sClass": "center",
					"render": function(data, type, row, meta) {
						if (row.status == 1) {
							return '<td>启用</td>'
						} else {
							return '<td><span>停用<span></td>'
						}
					}
				},
				{
					"mDataProp": "bindName",
					"sTitle": "车辆绑定人",
					"sDefaultContent": "",
					"sClass": "center"
				},
				{
					"mDataProp": "bindTime",
					"sTitle": "车辆绑定时间",
					"sDefaultContent": "",
					"sClass": "center"
				}
				/**,
				{
					"mDataProp": "creater",
					"sTitle": "创建人",
					"sDefaultContent": "",
					"sClass": "center"
				},
				{
					"mDataProp": "createTime",
					"sTitle": "创建时间",
					"sDefaultContent": "",
					"sClass": "center"
				},
				**/
				],
				
				"sAjaxSource": urlsVVehicleqrcode + "vgetTableList" /*"/apis/base/cashbox/getTableList"*/ ,
				//服务器端，数据回调处理  
				"fnRowCallback": function(nRow, aData, iDisplayIndex) {
					/* 用来改写用户权限的 */
					if (aData.companyid == '1')
						$('td:eq(3)', nRow).html('管理员');
					if (aData.companyid == '2')
						$('td:eq(3)', nRow).html('资料下载');
					if (aData.companyid == '3')
						$('td:eq(3)', nRow).html('一般用户');
					return nRow;
				},
				"fnServerData": function(sSource, aDataSet, fnCallback) {
					var list   = 	window.localStorage.getItem("baseinfo-vhicle-qrcode-user");
					if(username=="admin"){
						aDataSet = {
						}; 
					}else{
						
						$.ajax({
							type: 'get',
							url: urlsReport + '/getUserByname',
							data: {
								"username": username
							},
							async: false,
							beforeSend: function (request) {
											request.setRequestHeader("Authorization", "Bearer " + getToken());
										},
							dataType: 'json',
							success: function(data) {
								console.log(data.list);
								var list = eval('(' + data.list + ')');
								comId = list[0].companyId;
								var data = {};
								if (comId != '') {
									data.comid = comId;
								}
								data.order = 'serialNum';
								if(comId!=""&&comId!=null){
									aDataSet = data; 
								}else{
									aDataSet = {
										/* "boxNo": vm.msg,
										"like": "%boxNo%",
										"order": "id" */
									};
								}
							
							},
							error: function(data) {
								console.log(data.msg);
							}
						
						});
					}
					$.ajax({
						"dataType": 'json',
						"type": "GET",
						"url": sSource,
						"data": aDataSet,
						 "beforeSend": function(request) {
								request.setRequestHeader("Authorization", "Bearer " + getToken());
							}, 
						"success": fnCallback
					});
				}
			});

		

		

			/* 批量修改 */
			function vehicle_updateMoreById(title, url, id, w, h) {
				var ids = "";
				var serialNums = "";
				var chk_value =[];
				if ($(".check_item:checked").parents("tr").find("td:eq(3)").text() == '') {
					layer.open({
						title: '批量修改',
						content: '未选择任何修改项，请重新选择!'
					});
					return;
				} else {
					 $.each($(".check_item:checked"), function() {
						//newsName +=$(this).parents("tr").find("td:eq(3)").text()+",";
						serialNums += $(this).parents("tr").find("td:eq(3)").text() + ",";
						
					}); 
					$('input[name="qrcodeid"]:checked').each(function(){//遍历每一个名字为interest的复选框，其中选中的执行函数    
						chk_value.push($(this).val());//将选中的值添加到数组chk_value中   
							ids=ids+$(this).val()+","
						});
					localStorage.setItem("vehicleAll", ids);
					localStorage.setItem("serialNums", serialNums);
					layer_show(title, url + "?id=all", w, h);
				}
			};


	function delectVehicleQrcodeByIds() {
				var ids = "";
				var chk_value =[];
					$('input[name="qrcodeid"]:checked').each(function(){//遍历每一个名字为interest的复选框，其中选中的执行函数    
						chk_value.push($(this).val());//将选中的值添加到数组chk_value中   
							ids=ids+$(this).val()+","
						});
						if(ids==""){
							layer.open({
								title: '批量删除',
								content: '请选择!'
							});
						}else{
							var targetUrl  =  urlsVehicleqrcode + "delectVehicleQrcodeByIds";
							$.ajax({
								type: 'get',
								url: targetUrl,
								data: {
									"vhicles": ids
								},
								cache: false,
											
								dataType: 'json',
								success: function(data) {
									if(data.a==1){
										layer.msg("删除成功",{icon:1,time:1000});
										document.location.reload();
									}
								},
								error: function() {
								}
							});
						}
						
						
						
			};

			
				function submitall() {
								layer_show("生成","baseinfo-vehicle-qrcode-save.html",800,200);
						}
				function excelAll(){
					$("#list").table2excel({
								exclude: ".noExl",
								name: "Excel Document Name",
								filename: "myFileName",
								exclude_img: true,
								exclude_links: true,
								exclude_inputs: true
							});
				}
		</script>
	</body>

</html>
